package com.zwz.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.zwz.bean.SysRolesBean;
import com.zwz.model.SysRoles;
import com.zwz.service.baseConfig.SysRoleService;
import com.zwz.utils.FunctionUtils;

/**
 * 角色管理
 * @author zhangwanzhong
 * 2016年2月23日 下午2:39:42
 */
@Controller
@RequestMapping("/role")
public class SysRoleController extends BaseController {
	@Autowired
	private SysRoleService sysRoleService;
	
	@RequestMapping(value="getView")
	public String getView(HttpServletRequest request){
		request.setAttribute("roleAuth", getRoleAuth());
		return "role";
	}
	
	@RequestMapping(value="/queryByList")
	@ResponseBody
	public Object queryByList(SysRolesBean bean){
		List<SysRoles> dataList=sysRoleService.queryByList(bean);
		//设置页面数据
		Map<String,Object> jsonMap = new HashMap<String,Object>();
		jsonMap.put("total",bean.getPager().getRowCount());
		jsonMap.put("rows", dataList);
		return jsonMap;
	}
	
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Object add(SysRoles role){
		role.setId(FunctionUtils.getUUID());
		role.setStatus("0");
		sysRoleService.add(role);
		return sendSuccessMessage("处理成功");
	}
	
	@RequestMapping(value="/update",method=RequestMethod.POST)
	@ResponseBody
	public Object update(SysRoles role){
		role.setStatus("0");
		sysRoleService.update(role);
		return sendSuccessMessage("处理成功");
	}
	
	
	@RequestMapping(value="/delete")
	@ResponseBody
	public Object delete(String id){
		sysRoleService.delete(id);
		return sendSuccessMessage("删除成功");
	}
}
